home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Dev / misc / temgen.lha / Temgen / tg-0.11 / list.h < prev    next >
C/C++ Source or Header  |  2002-12-18  |  2KB  |  100 lines

  1. #ifndef _LINUX_LIST_H
  2. #define _LINUX_LIST_H
  3.  
  4. /* Stolen from linux kernel source,
  5.    added config.h here (checking for "inline")  */ 
  6. #include "config.h"
  7.  
  8. /*
  9.  * Simple doubly linked list implementation.
  10.  *
  11.  * Some of the internal functions ("__xxx") are useful when
  12.  * manipulating whole lists rather than single entries, as
  13.  * sometimes we already know the next/prev entries and we can
  14.  * generate better code by using them directly rather than
  15.  * using the generic single-entry routines.
  16.  */
  17.  
  18. struct list_head {
  19.     struct list_head *next, *prev;
  20. };
  21.  
  22. #define LIST_HEAD(name) \
  23.     struct list_head name = { &name, &name }
  24.  
  25. #define INIT_LIST_HEAD(ptr) do { \
  26.     (ptr)->next = (ptr); (ptr)->prev = (ptr); \
  27. } while (0)
  28.  
  29. /*
  30.  * Insert a new entry between two known consecutive entries. 
  31.  *
  32.  * This is only for internal list manipulation where we know
  33.  * the prev/next entries already!
  34.  */
  35. static inline void __list_add(struct list_head * new,
  36.     struct list_head * prev,
  37.     struct list_head * next)
  38. {
  39.     next->prev = new;
  40.     new->next = next;
  41.     new->prev = prev;
  42.     prev->next = new;
  43. }
  44.  
  45. /*
  46.  * Insert a new entry after the specified head..
  47.  */
  48. static inline void list_add(struct list_head *new, struct list_head *head)
  49. {
  50.     __list_add(new, head, head->next);
  51. }
  52.  
  53. /*
  54.  * Delete a list entry by making the prev/next entries
  55.  * point to each other.
  56.  *
  57.  * This is only for internal list manipulation where we know
  58.  * the prev/next entries already!
  59.  */
  60. static inline void __list_del(struct list_head * prev,
  61.                   struct list_head * next)
  62. {
  63.     next->prev = prev;
  64.     prev->next = next;
  65. }
  66.  
  67. static inline void list_del(struct list_head *entry)
  68. {
  69.     __list_del(entry->prev, entry->next);
  70. }
  71.  
  72. static inline int list_empty(struct list_head *head)
  73. {
  74.     return head->next == head;
  75. }
  76.  
  77. /*
  78.  * Splice in "list" into "head"
  79.  */
  80. static inline void list_splice(struct list_head *list, struct list_head *head)
  81. {
  82.     struct list_head *first = list->next;
  83.  
  84.     if (first != list) {
  85.         struct list_head *last = list->prev;
  86.         struct list_head *at = head->next;
  87.  
  88.         first->prev = head;
  89.         head->next = first;
  90.  
  91.         last->next = at;
  92.         at->prev = last;
  93.     }
  94. }
  95.  
  96. #define list_entry(ptr, type, member) \
  97.     ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
  98.  
  99. #endif
  100.